package com.tonyodev.fetch2core;

import org.jetbrains.annotations.NotNull;

import java.io.Closeable;
import java.io.IOException;

/**
 * Class that can be used to wrap an output Stream of file output resource.
 *
 * @since 2021-05-20
 */
public abstract class OutputResourceWrapper implements Closeable {
    /**
     * Write bytes to resource
     *
     * @param byteArray data
     * @param offSet write offset
     * @param length data length
     * @throws IOException io fail
     */
    public abstract void write(@NotNull byte[] byteArray, int offSet, int length) throws IOException;

    /**
     * Write bytes to resource
     *
     * @param byteArray data
     * @throws IOException io fail
     */
    public void write(byte[] byteArray) throws IOException {
        write(byteArray, 0, byteArray.length);
    }

    /**
     * Set write offset position
     *
     * @param offset write offset position
     * @throws IOException io fail
     */
    public abstract void setWriteOffset(long offset) throws IOException;

    /**
     * Flush resource buffer
     *
     * @throws IOException io fail
     */
    public abstract void flush() throws IOException;
}
